<template>
    <div>
        <Header></Header>
        <div class="m-blog">
            <h2>{{blog.title}}</h2>
            <el-link icon="el-icon-edit" v-if="ownBlog">
                <router-link :to="{name:'BlogEdit',params:{blogId:blog.id}}">
                    编辑
                </router-link>
            </el-link>
            <el-divider></el-divider>
            <div class="markdown-body" v-html="blog.content"></div>
        </div>
    </div>
</template>

<script>
    import Header from "../components/Header";
    import "github-markdown-css/github-markdown.css"

    export default {
        name: "BlogDetail.vue",
        components: {Header},
        data() {
            return {
                blog: {
                    title: 'girl',
                    description: '徐瑞',
                    content: "ls's whore"
                },
                ownBlog:false
            }
        },
        created() {
            const blogId = this.$route.params.blogId
            console.log(blogId)

            this.$axios.get('/blog/' + blogId).then(res => {
                const blog = res.data.data;
                let that = this;
                that.blog.id = blog.id
                that.blog.title = blog.title
                that.blog.description = blog.decription

                var markdownIt = require("markdown-it");
                var md = new markdownIt();

                var result = md.render(blog.content)
                that.blog.content = result

                that.ownBlog=(blog.userId===that.$store.getters.getUser.id)
            })

        }
    }
</script>

<style scoped>
    .m-blog {
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        width: 100%;
        min-height: 700px;
        padding: 20px 15px;

    }
</style>